package com.example.chatplatform.util;

import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;

public class MessageUtils {

    private static final ObjectMapper objectMapper = new ObjectMapper();

    public static String getMessage(Integer system, String type, Integer fromId, Object message) {
        try {
            // 创建一个 Map 来存储消息内容
            Map<String, Object> messageMap = new HashMap<>();
            messageMap.put("system", system);//(0系统，1非系统)
            messageMap.put("type", type);
            messageMap.put("fromId", fromId);
            messageMap.put("message", message);

            // 将 Map 转换为 JSON 字符串
            return objectMapper.writeValueAsString(messageMap);
        } catch (Exception e) {
            return null;
        }
    }

}
